
import java.io.IOException;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.LayerManager;
import javax.microedition.lcdui.game.Sprite;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author khang
 */
public class Conversation {
    Sprite enemy,player;
    int iwidth,iheight,nCon1,nCon2,nCon3,index;
    String[] conv1,conv2,conv3;
    public Conversation(LayerManager lm,int width,int height){
        this.player=player;
        this.enemy=enemy;
        iwidth=width;
        iheight=height;
        nCon1=7;
        nCon2=21;
        nCon3=4;
        index=0;
        conv1=new String[nCon1];
        conv1[0]="Hmph, it's so dark.";
        conv1[1]="This mysterious mist...";
        conv1[2]="...has blocked the sun.";
        conv1[3]="May be some kind of devil...";
        conv1[4]="...did it.";
        conv1[5]="I must do something unless...";
        conv1[6]="...the sun will never come back";
        conv2=new String[nCon2];
        conv2[0]="The darkness somehow...";
        conv2[1]="...make the scene's looked...";
        conv2[2]="so romantic"; 
        conv2[3]="Is it?";
        conv2[4]="That's why I've made this...";
        conv2[5]="...mist, hehe";
        conv2[6]="Who's there?";
        conv2[7]="Huh? Is anybody here?";
        conv2[8]="I'm asking you!!";
        conv2[9]="Oh I'm sorry, I'm Sakuya";
        conv2[10]="Nice to meet you";
        conv2[11]="Hmph, you're the one's...";
        conv2[12]="...spread this mist right";
        conv2[13]="Yes, no need to thanks me";
        conv2[14]="I'm not going to thanks you";
        conv2[15]="Your mist is blocking the sun";
        conv2[16]="You must stop it now!";
        conv2[17]="I don't like the sun";
        conv2[18]="I won't return it to you!";
        conv2[19]="So I have to defeat you!";
        conv2[20]="Try all you like!";
        conv3=new String[nCon3];
        conv3[0]="No,I lose!";
        conv3[1]="Now would you please stop...";
        conv3[2]="spreading this mist?";
        conv3[3]="O...Ok, I'm sorry lady"; 
        try {
            player=new Sprite(Image.createImage("/face00aE.png"), 25, 50);
            //int[]frameSequence={0,1};
            player.setFrame(0);
            player.setVisible(false);
            enemy=new Sprite(Image.createImage("/face09aE.png"), 25, 50);
            int[]frameSequence2={0,1};
            enemy.setFrameSequence(frameSequence2);
            enemy.setVisible(false);
            lm.append(player);
            lm.append(enemy);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    public String getCoversation2(int idx){
        return conv2[idx];
    }
    public void setIndex(int idx){
        index=idx;
    }
    public int getIndex(){
        return index;
    }
    public boolean  setConversation3(Graphics g,int scrY){
        if(index>=nCon3){
            player.setVisible(false);
            enemy.setVisible(false);
            return false;
        }
        player.setPosition(10, scrY+iheight-player.getHeight());
        enemy.setPosition(10, scrY+iheight-player.getHeight());
        if(index==1||index==2){
            enemy.setVisible(false);
            player.setVisible(true);
        }
        else{
            player.setVisible(false);
            enemy.setVisible(true);
        }
        g.setColor(255, 255, 255);
        g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL));
        g.drawString(conv3[index], 50, iheight-40, Graphics.TOP|Graphics.LEFT);
        return true;
    }
    public boolean  setConversation2(Graphics g,int scrY){
        if(index>=nCon2){
            player.setVisible(false);
            enemy.setVisible(false);
            return false;
        }
        player.setPosition(10, scrY+iheight-player.getHeight());
        enemy.setPosition(10, scrY+iheight-player.getHeight());
        if(index==0||index==1||index==2||index==6||index==8||index==11||index==12||index==14||index==15||index==16||index==19){
            enemy.setVisible(false);
            player.setVisible(true);
        }
        else if(index==9||index==10||index==13||index==17||index==18||index==20){
            player.setVisible(false);
            enemy.setVisible(true);
        }
        else{
            player.setVisible(false);
            enemy.setVisible(false);
        }
        g.setColor(255, 255, 255);
        g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL));
        g.drawString(conv2[index], 50, iheight-40, Graphics.TOP|Graphics.LEFT);
        return true;
    }
    public boolean  setConversation1(Graphics g,int scrY){
        if(index>=nCon1){
            player.setVisible(false);
            return false;
        }
        player.setPosition(10, scrY+iheight-player.getHeight());
        player.setVisible(true);
        g.setColor(255, 255, 255);
        g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL));
        g.drawString(conv1[index], 50, iheight-40, Graphics.TOP|Graphics.LEFT);
        return true;
    }
}
